let user = localStorage.user && JSON.parse(localStorage.user)
let body = document.querySelector('.body')
let dropdown = document.querySelector('.dropdown-lift')
let dropdowns = document.querySelector('.dropdown-right')
let title = document.querySelector('.tit')
let main = document.querySelector('.main')


console.log(localStorage.getItem("user"));

//发送请求，获取用户数据
renderContents()
async function renderContents(){
    let res = await axios({
        method:'get',
        url:'/api/user',
        params:{
            userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
        }
    })
    //渲染数据
    // console.log(res,localStorage.getItem("user"));
    
    if(res.data.code){
        alert(res.data.msg);
        return
    }
    let data = res.data.data

    renderUserList2(data) 
    function renderUserList2(data) {
    let reminds = '';
        reminds +=`
        <a href="" class="title">${data.username}</a>
        <span class="caret"></span>
        <ul class="userdisplay">
            <li>
                <a href="../lk/my-diary.html">我的日记</a>
            </li>
            <li>
                <a href="guanzhudereng.html">我关注的人</a>
            </li>
            <li>
                <a href="">设置</a>
            </li>
            <li>
                <a href="">退出</a>
            </li>
        </ul>
        `
    dropdowns.innerHTML = reminds
}



    let res1 = await axios({
        method:'get',
        url:'/api/user',
        params:{
            userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
        }
    })
    console.log(res1);
    let remind = '';
     remind +=`
                <a href="tixing.html" class="title">提醒(${0})</a>
                <span class="caret"></span>
                <ul class="msg">
                    <li>没有提醒</li>
                </ul>
            `
            dropdown.innerHTML = remind


            


    //  发送请求，获取关注用户的数量
    renderContents3()
    async function renderContents3(){
        let res3 = await axios({
            method:'get',
            url:'/api/user',
            params:{
                userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
            }
        })
        //渲染数据
        let data = res3.data.data
        // console.log( 111,res3.data.data);
        let id = data.idolId.length
        let ids = data.fansId.length
        if(data == null ){
            let html = '';
            html += `<a href="guanzhudereng.html">我关注的人(${0})</a>
                    <a href="guanzhugeren1.html">关注我的人(${0})</a>
                    `
                    title.innerHTML = html
            }else{
                    let html = '';
                    html += `
                    <a href="guanzhudereng.html">我关注的人(${id})</a>
                    <a href="guanzhugeren1.html">关注我的人(${ids})</a>
                            `
                    title.innerHTML = html
            }
    }


    //发送请求，获取关注用户
    renderContents4()
    async function renderContents4(){
        let res4 = await axios({
            method:'get',
            url:'/api/user',
            params:{
                userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
            }
        })
        
        //渲染数据
        let data = res4.data.data.idolId
        console.log(222,data);
        if(data == null ){
                return
            }else{
                console.log(123,data)
                let html = '';
                for (const item of data) {
                    console.log(1111,item);
                    let res = await axios({
                        method:'get',
                        url:'/api/user',
                        params:{
                            userId:`${item}`
                        }
                        
                    })
                    console.log(333,res.data.data);
                    let data = res.data.data
                    html += `
                        <div class="people">
                            <a href="">
                                <img src="http://localhost:8000${data.headphoto}" alt="">
                            </a>
                            <span>
                                <a href="">${data.username}</a>
                                <span class="guanzhu">
                                    <a href="">召唤好友</a>
                                    <button>取消关注</button>
                                </span>
                            </span>
                        </div>
                            `
                }
                body.innerHTML = html
            }
    }
}
